<?php
class site extends Mod
{
	public function __construct()
	{
		//$this = new self();
	}
	
	public function index($defParam = 0)
	{
		
		echo 'Good Luck!<br />@Wind Severn';
		//var_dump($this);
		
	}
	
	public function create()
	{
		$data = array(
			'root' => WWWROOT
		);
		$this->render('index', $data);
	}
	
	public function act_create()
	{
		$data = $_POST;
		$res = [];
		$dir = $data['dir'];
		$filename = $data['filename'];
		$filetype = $data['filetype'];
		$content = '<?php' .chr(13) . 'class ' . $filename . ' {' . chr(13) . chr(13) . '}';
		$isfile = false;
		$iswdir = false;
		switch($data['type'])
		{
			case 'php':
				$isfile = true;
				break;
			case 'file':
				$isfile = true;
				$content = '#New File';
				break;
			case 'view':
				$isfile = true;
				$content = '<!DOCTYPE html>' . chr(13) . '<html>' . chr(13) . '<head>' . chr(13) . '<title>New File</title>' . chr(13) . '</head>' . chr(13) . '<body>' . chr(13) . chr(13) . '</body>' . chr(13) . '</html>';
				break;
			case 'wdir':
				$iswdir = true;
				break;
		}
		if (!is_dir($dir)) {
			$res[] = mkdir($dir);
			if ($iswdir) chmod($dir, 0777);
		}
		$file = $dir . $filename . $filetype;
		var_dump($file);
		if($isfile && !file_exists($file)) $res[] = file_put_contents($file, $content);
		var_dump($res);
	}
	
	public function git()
	{
		echo '/etc/sudoers 增加www用户，NOPASSWD:ALL<br />';
		echo '/usr/local/php/etc/php.ini disable_functions 去除shell_exec<br />';
		echo 'PHP代码：shell_exec(\'sudo /shell/pwd.sh\')<br />';
		$e = shell_exec('sudo /shell/git-pull.sh'); 
		
		echo '返回结果是: ' . $e;exit;
	}
	
	public function test()
	{
		/*
		
		*/
		$sqlite = new Sqlite();
		$sqlite->connection('#test.db');
		$sqlite->sql = "select * from admin";
		var_dump($sqlite->rows());
		
	}
}